package dev.alm.spring01ioc.config;

import dev.alm.spring01ioc.datasource.DemoDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
public class DataSourceConfig {

    @Profile("dev")
    @Bean
    public DemoDataSource dev() {
        DemoDataSource dev = new DemoDataSource();
        dev.setUrl("jdbc:mysql://localhost:3306/dev");
        dev.setUsername("root");
        dev.setPassword("123456");
        dev.setDriverClassName("com.mysql.cj.jdbc.Driver");
        return dev;
    }

    @Profile("test")
    @Bean
    public DemoDataSource test() {
        DemoDataSource test = new DemoDataSource();
        test.setUrl("jdbc:mysql://localhost:3306/test");
        test.setUsername("root");
        test.setPassword("123456");
        test.setDriverClassName("com.mysql.cj.jdbc.Driver");
        return test;
    }

    @Profile("prod")
    @Bean
    public DemoDataSource prod() {
        DemoDataSource prod = new DemoDataSource();
        prod.setUrl("jdbc:mysql://localhost:3306/prod");
        prod.setUsername("root");
        prod.setPassword("123456");
        prod.setDriverClassName("com.mysql.cj.jdbc.Driver");
        return prod;
    }

    @Profile("default")
    @Bean
    public DemoDataSource defaultDataSource() {
        DemoDataSource defaultDataSource = new DemoDataSource();
        defaultDataSource.setUrl("jdbc:mysql://localhost:3306/default");
        defaultDataSource.setUsername("root");
        defaultDataSource.setPassword("123456");
        defaultDataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        return defaultDataSource;
    }
}
